package com.ncs.stm;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import com.ncs.stm.entity.User;
import com.ncs.stm.helper.HttpHelper;


public class MainActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }


    @Override
    protected void onResume() {
        super.onResume();
        LayoutInflater layoutInflater = getLayoutInflater();
        View view = layoutInflater.inflate(R.layout.login,null);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.login);
        builder.setView(view);
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.cancel,new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addCategory(Intent.CATEGORY_HOME);
                MainActivity.this.startActivity(intent);
            }
        });

        builder.setNegativeButton(R.string.login,new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                User user = HttpHelper.loginByGetDemo("http://192.168.82.163/STM/api/LogIn/Get/", User.class);
                if(user.getUserid() == null || "".equals(user.getUserid().trim())){
                    Intent intent = new Intent(MainActivity.this,SurveyTips.class);
                    intent.putExtra("userid","user001");
                    startActivity(intent);
                }else{
                    //todo summary activity
                }
            }
        });

        builder.show();
    }
}